package org.comeday.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult<T> implements Serializable {

    private static final long serialVersionUID = -5739212473655189440L;


    private String msg = "操作成功";

    private String code;

    private transient T data;

    private String businessType;

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> result = new CommonResult<>();
        result.setCode("00000");
        result.setData(data);
        result.setMsg("success");
        result.setBusinessType("common");
        return result;
    }

    public static <T> CommonResult<T> success() {
        return success(null);
    }

    public static <T> CommonResult<T> error(String msg) {
        CommonResult<T> result = new CommonResult<>();
        result.setCode("88888");
        result.setData(null);
        result.setMsg(msg);
        result.setBusinessType("common");
        return result;
    }

    public static <T> CommonResult<T> error(String errorCode, String msg) {
        CommonResult<T> result = error(msg);
        result.setCode(errorCode);
        return result;
    }

}
